<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderNo"/>
                            </li>
                            <li>
                                <label>状态</label>
                                <select name="status" th:with="type=${@dict.getType('orderStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="btime"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="etime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:order:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <!--<a class="btn btn-warning" id="importExcel">-->
                    <!--<i class="fa fa-download"></i> 导入发货单-->
                <!--</a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:order:remove')}]];
        var statusDatas = [[${@dict.getType('orderStatus')}]];
        var payTypeDatas = [[${@dict.getType('order_pay_type')}]];
        var prefix = ctx + "system/order";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "订单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'orderNo', 
                    title: '订单号'
                },
                {
                    field: 'userName',
                    title: '昵称'
                },
                    {
                        field: 'memberCar',
                        title: '姓名',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "-";
                            }else{
                                return value.name;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '电话',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "-";
                            }else{
                                return value.mobile;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '车牌号',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.licensePlate;
                            }
                        }
                    },
                    {
                        field: 'memberCar',
                        title: '车架号',
                        formatter: function (value,row,index) {
                            if(value==null){
                                return "未绑定";
                            }else{
                                return value.frameNo;
                            }
                        }
                    },
                {
                    field: 'priceRealPay', 
                    title: '订单金额(积分)'
                },
                {
                    field: 'status', 
                    title: '订单状态',
                    formatter: function(value, row, index) {
                      if (value == 0) {
                          return "待自提"
                      } else if (value == 1) {
                          return "待发货"
                      } else if (value == 2) {
                          return "待收货"
                      } else {
                          return "已完成"
                      }
                    }
                },
                {
                    field: 'created', 
                    title: '创建时间'
                },
                {
                    field: 'buyerMsg', 
                    title: '买家留言'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.payType==1){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }
                        if (row.status == 1){
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="send(\'' + row.id + '\')"><i class="fa fa-send"></i>发货</a>');
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="info(\'' + row.id + '\')"><i class="fa fa-info"></i>订单详情</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        // function send(id) {
        //     layer.confirm('确认已发货吗',{
        //         shade:[0.5,'#000'],
        //         shift:1,
        //         shadeClose:true,
        //         btn:['确认','取消'],
        //         yes: function (index,layero) {
        //             //执行 Ajax 后重载
        //             $.ajax({
        //                 url : prefix+"/send/"+id,
        //                 type : "post",
        //                 success : function(result) {
        //                     layer.close(index)
        //                     $.table.search()
        //                 },
        //                 error:function () {
        //                     layer.msg('失败',{'icon':2});
        //                 }
        //             });
        //         },btn2: function (index,layero) {
        //         }
        //     })
        // }
        function send(id) {
            $.modal.open("发货",ctx+"/system/order/send/"+id);
        }
        function info(id) {
            $.modal.open("订单详情", ctx+"/system/order/info/"+id);
        }



        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            upload.render({
                elem: '#importExcel'
                , url: ctx+'/system/order/importExcel' //改成您自己的上传接口
                ,accept: 'file'
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    layer.msg('上传成功')
                }
            });
        });
    </script>
</body>
</html>